﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FlickrSample.SL.Infrastructure;
using FlickrSample.SL.Infrastructure.Flickr.Entities;
using FlickrSample.View.Photo;
using XamlingCore.Infrastructure.View;

namespace FlickrSample.View.User
{
    public class UserDetailViewModel : XContentViewModelBase
    {
        private FlickrUser user;

        private List<PhotoSet> photoSets;

        private PhotoSet selectedSet;

        public override void OnInitialise()
        {
            Title = User.RealName;
            loadSets();
        }

        private void onSetSelected()
        {
            var model = CreateContentModel<PhotoSetViewModel>((newModel)=>
                                                                  {
                                                                      newModel.PhotoSet = selectedSet;
                                                                  });
            NavigateTo(model);
        }

        void loadSets()
        {
            IsLoading = true;
            ServiceLocator.UserRepo.GetPhotoSets(User, (sets) =>
                                                           {
                                                               PhotoSets = sets;
                                                               IsLoading = false;
                                                           });
        }

        public FlickrUser User
        {
            get { return user; }
            set { user = value; }
        }

        public List<PhotoSet> PhotoSets
        {
            get { return photoSets; }
            set
            {
                photoSets = value;
                OnPropertyChanged("PhotoSets");
            }
        }

        public PhotoSet SelectedSet
        {
            get { return selectedSet; }
            set
            {
                selectedSet = value;
                OnPropertyChanged("SelectedSet");
                onSetSelected();
            }
        }

      
    }
}
